package leetcode.code1726;

import leetcode.IDebug;
import leetcode.helper.HelpDebug;

/**
 * 超内存
 */
public class Solution implements IDebug {

	public int tupleSameProduct(int[] nums) {
		int ans = 0;
		int[] hash = new int[(int) 1e8 + 1];
		int len = nums.length;
		for (int i = 0; i < len - 1; i++) {
			for (int j = i + 1; j < len; j++) {
				int mul = nums[i] * nums[j];
				int count = hash[mul];
				if (count > 0) {
					ans += count;
				}
				hash[mul] += 1;
			}
		}
		return ans << 3;
	}

	@Override
	public void debug1() {
		HelpDebug.compare(8, this.tupleSameProduct(HelpDebug.str2array3("[2,3,4,6]")));

	}

	@Override
	public void debug2() {
		HelpDebug.compare(16, this.tupleSameProduct(HelpDebug.str2array3("[1,2,4,5,10]")));
	}

	@Override
	public void debug3() {
		HelpDebug.compare(40, this.tupleSameProduct(HelpDebug.str2array3("[2,3,4,6,8,12]")));
	}

	@Override
	public void debug4() {
		HelpDebug.compare(0, this.tupleSameProduct(HelpDebug.str2array3("[2,3,5,7]")));
	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
